﻿using System;
using System.Collections.Generic;
using LoA.Shared.Screen;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace LoA.Screen {
	public partial class ScreenManager : DrawableGameComponent {
		private static ScreenManager _current = null;
		public static ScreenManager Current { get { return _current; } }

		public ScreenManager(Game game)
			: base(game) {
			if (_current == null)
				_current = this;
		}

		public GameState GameState { get; private set; }
		private IScreen currentScreen { get { if (this.screensTrace.Count > 0) return this.screensTrace.Peek( ); else return this.rootScreen; } }
		private IPopupScreenEntry currentPopup { get { if (this.popupsTrace.Count > 0) return this.popupsTrace.Peek( ); else return null; } }
		private Stack<IPopupScreenEntry> popupsTrace;
		private Stack<IScreen> screensTrace;
		private Stack<int> entriesTrace;
		private IPopupScreenEntry suspendPopup;
		private IScreen rootScreen;
		private int selectedEntry;

		private Texture2D menuBackgroundTexture;
		private Texture2D messageGradientTexture;
		//private SpriteFont spriteFont;
		private KeyboardState previousCurrentKeyboardState;
		private GamePadState previousCurrentGamePadSate;

		public override void Initialize( ) {
			base.Initialize( );

			this.popupsTrace = new Stack<IPopupScreenEntry>( );
			this.screensTrace = new Stack<IScreen>( );
			this.entriesTrace = new Stack<int>( );
			this.selectedEntry = 0;
		}

		protected override void LoadContent( ) {
			menuBackgroundTexture = Game.Content.Load<Texture2D>(@"Texture\Menu\MenuBackground");
			messageGradientTexture = Game.Content.Load<Texture2D>(@"Texture\Menu\MessageGradient");
			//spriteFont = Game.Content.Load<SpriteFont>(@"Interface\Fonts\MenuFont");
			rootScreen = Game.Content.Load<IScreen>("menu");
			suspendPopup = Game.Content.Load<IPopupScreenEntry>("suspendMenu");

			base.LoadContent( );
		}
		protected override void UnloadContent( ) {
			base.UnloadContent( );
		}
	}
}